<template>
	<el-dialog title="创建子条件" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="condition" :rules="rules" ref="conditionForm" label-width="100px" label-position="left">
			<el-form-item label="判断项" prop="field">
				<el-select v-model="condition.field" style="width: 100%;" @change="onFieldsChange">
					<el-option
						v-for="item in formFieldList"
						:key="item.id"
						:label="item.label"
						:value="item.id">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="判断方式">
				<el-select v-model="condition.optionPer">
					<el-option
						v-for="item in perOptions"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="对比值">
				<el-input v-model="condition.value" placeholder="对比值"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="addChild()">添 加</el-button>
		</template>
	</el-dialog>
</template>
<script>
export default {
	emits: ['success', 'closed'],
	props:{
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			stepId:'',
			formFieldList:[],
			conditionFields:[
				{id:"[发起人姓名]",label:"[发起人姓名]"},
				{id:"[发起人账号]",label:"[发起人账号]"},
				{id:"[发起人部门]",label:"[发起人部门]"},
				{id:"[发起人行政级别]",label:"[发起人行政级别]"},
				{id:"[主办人会签意见]",label:"[主办人会签意见]"},
				{id:"[当前步骤自增ID号]",label:"[当前步骤自增ID号]"},
				{id:"[当前步骤名称]",label:"[当前步骤名称]"},
				{id:"[当前主办人姓名]",label:"[当前主办人姓名]"},
				{id:"[当前主办人账号]",label:"[当前主办人账号]"},
				{id:"[当前主办人行政级别]",label:"[当前主办人行政级别]"},
				{id:"[当前主办人部门]",label:"[当前主办人部门]"}
			],
			perOptions:[
				{value: "等于", label: '等于'},
				{value: "不等于", label: '不等于'},
				{value: "大于", label: '大于'},
				{value: "大于等于", label: '大于等于'},
				{value: "小于", label: '小于'},
				{value: "小于等于", label: '小于等于'},
				{value: "以字符开头", label: '以字符开头'},
				{value: "以字符结尾", label: '以字符结尾'},
				{value: "包含", label: '包含'},
				{value: "不包含", label: '不包含'},
			],
			condition:{
				field:'',
				title:'',
				optionPer:'等于',
				value:''
			},
			rules:{
				field: [
					{required: true, message: '请选择判断项', trigger: 'blur'}
				],
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(){
			this.visible = true;
			return this
		},
		addChild()
		{
			this.$refs.conditionForm.validate((valid) => {
				if (valid) {
					this.visible = false;
					this.$emit('success', this.condition)
				}
			})

		},
		onFieldsChange(val)
		{
			var obj = {};
			obj = this.formFieldList.find(function(item) {
				return item.id === val;
			});
			this.condition.title = obj.label;
		},
		async setConditionFields(flowId)
		{
			let res = await this.$API.bpm.bpmForm.getBpmFormFieldsListForSelect.get({flowId: flowId});
			if (res.code == 200) {
				if (res.data == undefined) {
					this.$alert("未能检测到表单字段", "提示", {type: 'error'})
				} else {
					this.formFieldList=this.conditionFields.concat(res.data);
				}
			}
		},
	}
}
</script>
